import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

//引入路由组件
import {constantRoutes} from './routes';

//创建路由器对象的函数--路由器的初始化操作
const createRouter = () => new Router({
  // mode: 'history', // 路由的模式
  scrollBehavior: () => ({ y: 0 }), //设置初始滚动的纵坐标
  routes: constantRoutes //注册常量路由
})

const router = createRouter() //实例化路由器

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
//重置路由器
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
